//
//  Tools.m
//  OpenSSLDemo
//
//  Created by Andney Jack on 2021/5/11.
//

#import "Tools.h"

@implementation Tools

+ (NSString *)dataToHex:(NSData *)data
{
    if (data && data.length > 0) {
        NSMutableString *result = [[NSMutableString alloc] initWithCapacity:data.length];

        char *dataBytes = (char *)data.bytes;
        for (NSInteger i = 0; i < data.length; i++) {
            if (result.length > 0 && result.length % 64 == 0) {
                [result appendString:@"\n"];
            }
            [result appendFormat:@"%02x", dataBytes[i] & 0xff];
        }
        return result;
    }
    return @"";
}

@end
